//
//  DatabaseOperate.cpp
//  MMS
//
//  Created by 王翛然 on 16/8/9.
//  Copyright © 2016年 王翛然. All rights reserved.
//

#include "DatabaseOperate.hpp"

bool DatabaseOp::connect(const char *host, const char *user,
                         const char *password, const char *db,
                         unsigned int port,
                         const char *unix_socket,
                         unsigned long flag)
{
    if (mysql_real_connect(&mysql, host, user,
                           password, db, port,
                           unix_socket, flag) != nullptr)
        return true;
    return false;
}

int DatabaseOp::executeSql(const std::string &sql)
{
    mysql_query(&mysql, "set names utf8");
    return mysql_query(&mysql, sql.data());
}

MYSQL_RES* DatabaseOp::fetchResult()
{
    MYSQL_RES* result = mysql_store_result(&mysql);
    return result;
}